package com.zsp.coupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 优惠卷分类
 */

@Getter
//@AllArgsConstructor
public enum CouponCategory {

    MANNJIAN("满减卷","001"),
    ZHEKOU("折扣卷","002"),
    LIJIAN("立减卷","003");

    /**  优惠卷描述分类*/
 private String descrption;
    /**  优惠卷分类编码*/
 private String code;

    CouponCategory(String descrption, String code) {
        this.descrption = descrption;
        this.code = code;
    }

    public String getDescrption() {
        return descrption;
    }

    public String getCode() {
        return code;
    }

    public static CouponCategory of(String code){
     Objects.requireNonNull(code);
     return Stream.of(values()).filter(bean -> bean.code.equals(code))
             .findAny()
             .orElseThrow(() -> new IllegalArgumentException(code+"not exist"));
 }

}
